﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hotel
{
    public partial class Statistics : Form
    {
        public Statistics()
        {
            InitializeComponent();
        }
        CNDatabase cnDb = new CNDatabase();
        private void btStatistics_Click(object sender, EventArgs e)
        {
            string qr="select distinct Room.IDRoom ,NameRoom, COUNT(ListRoomBooking.IDRoom)'Stayed Times' "
                    +" ,sum(ListRoomBooking.Cost)'Income' from Room "
                    +" join ListRoomBooking on ListRoomBooking.IDRoom= Room.IDRoom "
                    + " and StartDay between CONVERT(datetime, '"+txtStart.Text+"', 103) and CONVERT(datetime, '"+txtEndDate.Text+"', 103) "
                    +" group by Room.IDRoom, NameRoom";
            grvStatistics.DataSource = cnDb.getDataset(qr).Tables[0];

            string qrTotal = "select  SUM(ListRoomBooking.Cost) from ListRoomBooking where   "
                    + " StartDay between CONVERT(datetime, '" + txtStart.Text + "', 103) and CONVERT(datetime, '" + txtEndDate.Text + "', 103) ";
            try
            {
                lbTotalCost.Text = "Total Cost: $ " + cnDb.getOneData(qrTotal).ToString();
            }
            catch (Exception) {
                cnDb.closeConnect();
                lbTotalCost.Text = "Total Cost: $ 0";
            }
        }

        private void Statistics_Load(object sender, EventArgs e)
        {
            LbCurrentDay.Text = "Today is " + DateTime.Today.ToString("dd/MM/yyyy");
        }
    }
}
